/** 
 * @file I2C.h
 * 
 * @detail Description : 
 * I2C driver
 * 
 * @author E. Macias / D. Torres / S. Ravindran
 * @author Texas Instruments, Inc
 * @date December, 2011
 * @version 1.0 - Initial version
 * @note Built with IAR Embedded Workbench: 5.20.1 and CCS Version 5.1.0.09000
 **/

#ifndef I2C_H_
#define I2C_H_ 

#include "Device.h"

// Local Variables
// @brief tx_packet_length is how many bytes of data will be written
extern uint8_t tx_packet_length;
// @brief *tx_packet_data will point to the data to be written
extern uint8_t *tx_packet_data;

// @brief rx_packet_length is how many bytes of data will be read
extern uint8_t rx_packet_length;
// @brief *rx_packet_data will point to the data to be read
extern uint8_t *rx_packet_data;

// @brief receive flag is used for the ISR to know the MSP430 will be reading from the
// CP
extern uint8_t receive_flag;
// @brief transmit flag is used for the ISR to know the MSP430 will be writing to the
// CP
extern uint8_t transmit_flag;

// @brief Used to keep track how many bytes have been received
extern uint8_t rx_byte_ctr;
// @brief Used to keep track how many bytes have been transmitted
extern uint8_t tx_byte_ctr;

// I2C Settings for master initialization
//****************************************************************************//
#define 	I2C_SOURCE_CLOCK		0x00	// 0x00 SMCLK or 0x01 ACLK
// Comment out the source clock which will not be used
#define		I2C_SOURCE_CLOCK_FREQ  SMCLK_FREQ
//#define     SPI_SOURCE_CLOCK_FREQ  ACLK_FREQ
#define		I2C_CLOCK_FREQ			400000  
//****************************************************************************//


// Global Functions
extern void I2C_Master_Init(void);

extern void I2C_Set_Slave_Address(uint8_t slaveAddress);
extern void I2C_Enable(void);
extern void I2C_Disable(void);
extern void I2C_Set_Mode(uint16_t receive);
extern uint16_t I2C_Bus_Busy(void);
extern uint16_t I2C_Busy(void);
extern void I2C_Interrupt_Enable(uint8_t interruptFlags);
extern void I2C_Interrupt_Disable(uint8_t interruptFlags);
extern void I2C_Interrupt_Clear(uint8_t interruptFlags);
extern unsigned char I2C_Interrupt_Status(uint8_t mask);   
extern void I2C_Write_Packet_To_Sensor(uint8_t *writeData,
                                       uint8_t dataLength);

extern void I2C_Read_Packet_From_Sensor(uint8_t *readData,
					uint8_t dataLength);

#endif /*I2C_H_*/

